#include "ActionApiKickPlayer.h"
#include "json.h"
#include "util.h"
#include "streamdata.h"
#include "agency_service.h"
#include "agencymgr.h"
#include "account_service.h"
#include "3400_api_order.pb.h"
#include "api_order_service.h"


static std::map<std::string,std::string> http_json_heads = {{"Content-Type","application/json"}};

static bool __init__ = ActionApiKickPlayer::Init();

bool ActionApiKickPlayer::Init()
{
    Ctx.msg_router.BindMsg(agency_api::AGENCY_API_MSGID_KICK_PLAYER, ActionApiKickPlayer::HandleMsg);

    return true;
}

void ActionApiKickPlayer::HandleMsg(MsgData&& msg_data)
{
    agency_api::KickPlayerPush push;

    do {
        if (!push.ParseFromArray(msg_data.data.data(), msg_data.data.size()))
        {
            log_error("parser msg failed");
            break;
        }
        log_debug("push:%s", push.ShortDebugString().c_str());

        std::uint32_t event_id = 0;
        // 请求http网络
        if (!Ctx.msg_router.sendHttpGET(push.kick_url(), "", http_json_heads, event_id) || (event_id == 0))
        {
            log_error("net get failed,url:%s", push.kick_url().c_str());
            break;
        }
        // 添加回调监听
        Ctx.msg_router.AddCurlEvent(event_id, [url=push.kick_url()] (std::string& body, bool is_ok){
            log_debug("url:%s,body:%s,is_ok:%d", url.c_str(), body.c_str(), is_ok);
        });

        return;
    } while(false);
}
